﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using Xpom_Xpum__Integrated_Development_Environment.Model;

namespace Xpom_Xpum__Integrated_Development_Environment.ViewModel
{
    public class NewItemWindowViewModel : ViewModel
    {
        #region Constructor

        public NewItemWindowViewModel()
        {
            mTemplates = new List<ItemTemplate>();

            var tzpath = AppDomain.CurrentDomain.BaseDirectory + "Item Templates/";
            foreach (var d in Directory.GetDirectories(tzpath))
            {
                if (File.Exists(d + "\\ItemTemplate.json"))
                {
                    var t = JsonConvert.DeserializeObject<ItemTemplate>(File.ReadAllText(d + "\\ItemTemplate.json"));

                    if (t.ItemTemplateNameEN == "Script")
                    {
                        ScriptItemTemplate = t;
                    }
                    else if (t.ItemTemplateNameEN == "HTML File")
                    {
                        HTMLItemTemplate = t;
                    }
                    else if (t.ItemTemplateNameEN == "CSS Style")
                    {
                        CSSItemTemplate = t;
                    }
                    else if (t.ItemTemplateNameEN == "Folder")
                    {
                        FolderItemTemplate = t;
                    }

                    mTemplates.Add(t);
                }
            }

            if (mTemplates.Count > 0)
            {
                SelectedItem = mTemplates[0];
            }
        }

        #endregion

        #region Commands

        #endregion

        #region Fields

        public List<ItemTemplate> mTemplates;

        public ItemTemplate mSelectedItem;

        #endregion

        #region Properties

        public List<ItemTemplate> ItemTemplates
        {
            get
            {
                return mTemplates;
            }
        }

        public ItemTemplate SelectedItem
        {
            get
            {
                return mSelectedItem;
            }
            set
            {
                mSelectedItem = value;
                OnPropertyChanged("SelectedItem");
            }
        }

        public ItemTemplate HTMLItemTemplate { get; set; }

        public ItemTemplate CSSItemTemplate { get; set; }

        public ItemTemplate ScriptItemTemplate { get; set; }

        public ItemTemplate FolderItemTemplate { get; set; }

        #endregion

        #region Methods

        #endregion

    }
}
